<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>导师管理中心 - 算力平台</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
        }

        /* 头部信息栏 */
        .header {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            padding: 30px;
            margin-bottom: 30px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
        }

        .header-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 20px;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .avatar {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            font-weight: bold;
        }

        .user-details h1 {
            font-size: 24px;
            color: #2d3748;
            margin-bottom: 5px;
        }

        .user-details p {
            color: #718096;
            font-size: 14px;
        }

        .header-actions {
            display: flex;
            gap: 15px;
        }

        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 10px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-primary {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
        }

        .btn-secondary {
            background: #e2e8f0;
            color: #4a5568;
        }

        .btn-secondary:hover {
            background: #cbd5e0;
        }

        .btn-danger {
            background: #fc8181;
            color: white;
        }

        .btn-danger:hover {
            background: #f56565;
        }

        /* 主要内容区域 */
        .main-content {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
        }

        @media (max-width: 1024px) {
            .main-content {
                grid-template-columns: 1fr;
            }
        }

        .card {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 2px solid #e2e8f0;
        }

        .card-title {
            font-size: 20px;
            font-weight: 600;
            color: #2d3748;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .badge {
            background: #667eea;
            color: white;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 500;
        }

        /* 报告设置部分 */
        .report-settings {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .setting-item {
            background: #f7fafc;
            padding: 20px;
            border-radius: 12px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            transition: all 0.3s ease;
        }

        .setting-item:hover {
            background: #edf2f7;
            transform: translateX(5px);
        }

        .setting-info {
            flex: 1;
        }

        .setting-title {
            font-size: 16px;
            font-weight: 500;
            color: #2d3748;
            margin-bottom: 5px;
        }

        .setting-desc {
            font-size: 13px;
            color: #718096;
        }

        .switch {
            position: relative;
            display: inline-block;
            width: 50px;
            height: 26px;
        }

        .switch input {
            opacity: 0;
            width: 0;
            height: 0;
        }

        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #cbd5e0;
            transition: .4s;
            border-radius: 26px;
        }

        .slider:before {
            position: absolute;
            content: "";
            height: 18px;
            width: 18px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
        }

        input:checked + .slider {
            background: linear-gradient(135deg, #667eea, #764ba2);
        }

        input:checked + .slider:before {
            transform: translateX(24px);
        }

        /* 学生审批部分 */
        .applications-list {
            display: flex;
            flex-direction: column;
            gap: 15px;
            max-height: 500px;
            overflow-y: auto;
            padding-right: 10px;
        }

        .applications-list::-webkit-scrollbar {
            width: 6px;
        }

        .applications-list::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 10px;
        }

        .applications-list::-webkit-scrollbar-thumb {
            background: #cbd5e0;
            border-radius: 10px;
        }

        .applications-list::-webkit-scrollbar-thumb:hover {
            background: #a0aec0;
        }

        .application-item {
            background: #f7fafc;
            padding: 20px;
            border-radius: 12px;
            border-left: 4px solid #667eea;
            transition: all 0.3s ease;
        }

        .application-item:hover {
            background: #edf2f7;
            transform: translateX(5px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
        }

        .application-header {
            display: flex;
            justify-content: space-between;
            align-items: start;
            margin-bottom: 12px;
        }

        .student-name {
            font-size: 16px;
            font-weight: 600;
            color: #2d3748;
        }

        .application-time {
            font-size: 12px;
            color: #a0aec0;
        }

        .application-details {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 10px;
            margin-bottom: 15px;
        }

        .detail-item {
            font-size: 13px;
            color: #4a5568;
        }

        .detail-label {
            font-weight: 500;
            color: #718096;
        }

        .application-actions {
            display: flex;
            gap: 10px;
            justify-content: flex-end;
        }

        .btn-small {
            padding: 8px 16px;
            font-size: 13px;
        }

        .btn-approve {
            background: #48bb78;
            color: white;
        }

        .btn-approve:hover {
            background: #38a169;
        }

        .btn-reject {
            background: #f56565;
            color: white;
        }

        .btn-reject:hover {
            background: #e53e3e;
        }

        /* 统计卡片 */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 15px;
            margin-bottom: 25px;
        }

        .stat-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            padding: 20px;
            border-radius: 12px;
            color: white;
        }

        .stat-value {
            font-size: 28px;
            font-weight: bold;
            margin-bottom: 5px;
        }

        .stat-label {
            font-size: 13px;
            opacity: 0.9;
        }

        /* 空状态 */
        .empty-state {
            text-align: center;
            padding: 40px;
            color: #a0aec0;
        }

        .empty-icon {
            font-size: 48px;
            margin-bottom: 15px;
        }

        .empty-text {
            font-size: 14px;
        }

        /* 保存按钮区域 */
        .save-settings {
            margin-top: 25px;
            padding-top: 20px;
            border-top: 2px solid #e2e8f0;
            display: flex;
            justify-content: flex-end;
        }

        /* 加载动画 */
        .loading {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s ease-in-out infinite;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        /* 成功提示 */
        .success-message {
            background: #48bb78;
            color: white;
            padding: 15px 20px;
            border-radius: 10px;
            margin-bottom: 20px;
            display: none;
            align-items: center;
            gap: 10px;
        }

        .success-message.show {
            display: flex;
            animation: slideDown 0.3s ease;
        }

        @keyframes slideDown {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 成功消息提示 -->
        <div class="success-message" id="successMessage">
            <span>✓</span>
            <span id="successText">操作成功！</span>
        </div>

        <!-- 头部信息 -->
        <div class="header">
            <div class="header-content">
                <div class="user-info">
                    <div class="avatar">{{ supervisor.name[0] }}</div>
                    <div class="user-details">
                        <h1>{{ supervisor.name }} 导师</h1>
                        <p>{{ supervisor.department }} · {{ supervisor.research_area }}</p>
                        <p style="margin-top: 5px; font-size: 12px;">{{ supervisor.email }}</p>
                    </div>
                </div>
                <div class="header-actions">
                    <a href="/" class="btn btn-secondary">
                        <span>🏠</span> 返回首页
                    </a>
                    <a href="/supervisor/logout" class="btn btn-danger">
                        <span>🚪</span> 退出登录
                    </a>
                </div>
            </div>
        </div>

        <!-- 主要内容 -->
        <div class="main-content">
            <!-- 左侧：报告设置 -->
            <div class="card">
                <div class="card-header">
                    <h2 class="card-title">
                        <span>📊</span> 资源使用报告设置
                    </h2>
                </div>
                
                <!-- 统计信息 -->
                <div class="stats-grid">
                    <div class="stat-card">
                        <div class="stat-value">{{ approved_students|length }}</div>
                        <div class="stat-label">课题组成员</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-value">{{ pending_applications|length }}</div>
                        <div class="stat-label">待审批申请</div>
                    </div>
                </div>

                <!-- 报告设置表单 -->
                <form id="settingsForm" method="POST" action="/supervisor/settings">
                    <div class="report-settings">
                        <div class="setting-item">
                            <div class="setting-info">
                                <div class="setting-title">月度资源使用报告</div>
                                <div class="setting-desc">每月初接收上月课题组成员的计算资源使用统计报告</div>
                            </div>
                            <label class="switch">
                                <input type="checkbox" name="monthly_report" id="monthlyReport" 
                                       {% if supervisor.receive_monthly_report %}checked{% endif %}>
                                <span class="slider"></span>
                            </label>
                        </div>

                        <div class="setting-item">
                            <div class="setting-info">
                                <div class="setting-title">季度资源使用报告</div>
                                <div class="setting-desc">每季度接收详细的资源使用分析报告，包含趋势分析</div>
                            </div>
                            <label class="switch">
                                <input type="checkbox" name="quarterly_report" id="quarterlyReport"
                                       {% if supervisor.receive_quarterly_report %}checked{% endif %}>
                                <span class="slider"></span>
                            </label>
                        </div>
                    </div>

                    <div class="save-settings">
                        <button type="submit" class="btn btn-primary" id="saveBtn">
                            <span>💾</span> 保存设置
                        </button>
                    </div>
                </form>
            </div>

            <!-- 右侧：学生审批 -->
            <div class="card">
                <div class="card-header">
                    <h2 class="card-title">
                        <span>👥</span> 学生申请审批
                    </h2>
                    <span class="badge">{{ pending_applications|length }} 待处理</span>
                </div>

                {% if pending_applications %}
                <div class="applications-list">
                    {% for app in pending_applications %}
                    <div class="application-item">
                        <div class="application-header">
                            <div class="student-name">{{ app.name }}</div>
                            <div class="application-time">{{ app.submitted_at.strftime('%Y-%m-%d %H:%M') }}</div>
                        </div>
                        <div class="application-details">
                            <div class="detail-item">
                                <span class="detail-label">学号：</span>{{ app.student_id }}
                            </div>
                            <div class="detail-item">
                                <span class="detail-label">邮箱：</span>{{ app.email }}
                            </div>
                            <div class="detail-item">
                                <span class="detail-label">用户名：</span>{{ app.username }}
                            </div>
                        </div>
                        <div class="application-actions">
                            <form method="POST" action="/supervisor/approve_student/{{ app.id }}" style="display: inline;">
                                <input type="hidden" name="action" value="approve">
                                <button type="submit" class="btn btn-small btn-approve">
                                    <span>✓</span> 批准
                                </button>
                            </form>
                            <form method="POST" action="/supervisor/approve_student/{{ app.id }}" style="display: inline;">
                                <input type="hidden" name="action" value="reject">
                                <button type="submit" class="btn btn-small btn-reject">
                                    <span>✗</span> 拒绝
                                </button>
                            </form>
                        </div>
                    </div>
                    {% endfor %}
                </div>
                {% else %}
                <div class="empty-state">
                    <div class="empty-icon">📭</div>
                    <div class="empty-text">暂无待审批的学生申请</div>
                </div>
                {% endif %}
            </div>
        </div>
    </div>

    <script>
        // 设置表单提交处理
        document.getElementById('settingsForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const saveBtn = document.getElementById('saveBtn');
            const originalText = saveBtn.innerHTML;
            saveBtn.innerHTML = '<span class="loading"></span> 保存中...';
            saveBtn.disabled = true;
            
            // 模拟异步提交
            setTimeout(() => {
                // 实际提交表单
                this.submit();
            }, 500);
        });

        // 显示成功消息（如果URL参数中有success）
        const urlParams = new URLSearchParams(window.location.search);
        if (urlParams.get('success')) {
            const successMessage = document.getElementById('successMessage');
            const successText = document.getElementById('successText');
            
            if (urlParams.get('success') === 'settings') {
                successText.textContent = '报告设置已保存成功！';
            } else if (urlParams.get('success') === 'approve') {
                successText.textContent = '学生申请已批准！';
            } else if (urlParams.get('success') === 'reject') {
                successText.textContent = '学生申请已拒绝！';
            }
            
            successMessage.classList.add('show');
            setTimeout(() => {
                successMessage.classList.remove('show');
            }, 3000);
        }

        // 添加审批按钮的确认对话框
        document.querySelectorAll('.btn-approve, .btn-reject').forEach(btn => {
            btn.addEventListener('click', function(e) {
                const action = this.classList.contains('btn-approve') ? '批准' : '拒绝';
                if (!confirm(`确定要${action}这个申请吗？`)) {
                    e.preventDefault();
                }
            });
        });
    </script>
</body>
</html>